import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
import { Session,Local } from '/@/utils/storage';
import { commApi } from '/@/api/comm/index';


/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 */
const userInfos = Local.get('userInfo')
export const useUserInfo = defineStore('userInfo', {
	state: () => ({
		authBtnList: [],
		userInfos: userInfos,
	}),
	actions: {
		async getBtnAuth(){
			try {
				let res = await commApi().getButtonAuth()
				this.authBtnList = res.data
			} catch (error) {
				
			}
		},
		async setUserInfos(userInfos) {
			this.userInfos = userInfos;
		},

		// 模拟接口数据
		// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
		async getApiUserInfo() {
			return new Promise((resolve) => {
				setTimeout(() => {
					// // 用户信息模拟数据
					// const userInfos = {
					// 	userName: userName,
					// 	photo:userName === 'admin'
					// 			? 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500'
					// 			: 'https://img2.baidu.com/it/u=2370931438,70387529&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
					// 	time: new Date().getTime(),
					// };
					// Session.set('userInfo', userInfos);
					// resolve(userInfos);
				}, 0);
			});
		},
	},
});
